//package com.rongji.egov.fileupload.s3.web;
//
//import com.rongji.egov.fileupload.s3.domain.Result;
//import com.rongji.egov.fileupload.s3.utils.ConvertOp;
//import com.rongji.egov.fileupload.s3.utils.S3Util;
//import org.dom4j.Document;
//import org.dom4j.DocumentHelper;
//import org.dom4j.Element;
//import org.dom4j.io.OutputFormat;
//import org.dom4j.io.XMLWriter;
//import org.springframework.http.MediaType;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.*;
//import org.springframework.web.multipart.MultipartFile;
//
//import javax.annotation.Resource;
//import javax.servlet.http.HttpServletRequest;
//import java.io.StringWriter;
//import java.util.Map;
//
//@RestController
//@RequestMapping("/s3")
//public class FileUploadControllerBk {
//    @Resource
//    private S3Util s3Util;
//
//    @GetMapping("/")
//    public ResponseEntity<String> listBuckets() throws Exception {
//        String xml = "";
//        Document doc = DocumentHelper.createDocument();
//        Element root = doc.addElement("ListAllMyBucketsResult");
//        Element owner = root.addElement("Owner");
//        Element id = owner.addElement("ID");
//        id.setText("20230529");
//        Element displayName = owner.addElement("DisplayName");
//        displayName.setText("admin");
//        Element buckets = root.addElement("Buckets");
//        for (int i=0 ; i< 1; i++) {
//            Element bucket = buckets.addElement("Bucket");
//            Element name = bucket.addElement("Name");
//            name.setText(i + "");
//            Element creationDate = bucket.addElement("CreationDate");
//            creationDate.setText(i + "");
//        }
//        OutputFormat format = OutputFormat.createPrettyPrint();
//        format.setEncoding("utf-8");
//        StringWriter out;
//        out = new StringWriter();
//        XMLWriter writer = new XMLWriter(out, format);
//        writer.write(doc);
//        writer.close();
//        xml = out.toString();
//        out.close();
//        return ResponseEntity.ok().contentType(MediaType.APPLICATION_XML).body(xml);
//    }
//
//    @PostMapping("/upload")
//    @ResponseBody
//    public Result upload(@RequestParam("file") MultipartFile file, HttpServletRequest request) throws Exception {
//        //String bucketName = request.getParameter("bucketName");
//        String key = request.getParameter("key");
//        s3Util.upload(key, file.getBytes());
//        return Result.okResult();
//    }
//
//    @PostMapping("/getFileBytes")
//    @ResponseBody
//    public Result getFileBytes(@RequestBody Map<String, Object> params) throws Exception {
//        String bucketName = ConvertOp.convert2String(params.get("bucketName"));
//        String key = ConvertOp.convert2String(params.get("key"));
//
//
//        byte[] data = s3Util.getFile(key);
//        return Result.okResult().add("obj", data);
//    }
//
//    @PostMapping("/delete")
//    @ResponseBody
//    public Result delete(@RequestBody Map<String, Object> params) throws Exception {
//        String bucketName = ConvertOp.convert2String(params.get("bucketName"));
//        String key = ConvertOp.convert2String(params.get("key"));
//        s3Util.deleteFile(key);
//        return Result.okResult();
//    }
//}
